#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <gmp.h>

#define pontos 10000000

int main(void){
	//Declaração de variáveis locais
	long long i;
    clock_t start,end;

	mpf_t x, y, z, pi, pCirc, aux1, aux2;
	mpf_init2(x,35000000);
	mpf_init2(y,35000000);
	mpf_init2(z,35000000);
	mpf_init2(pi,35000000);
	mpf_init2(pCirc,35000000);
	mpf_init2(aux1,35000000);
	mpf_init2(aux2,35000000);
    gmp_randstate_t state;

	mpf_set_d(x,0);
	mpf_set_d(y,0);
	mpf_set_d(z,0);
	mpf_set_d(pi,0);
	mpf_set_d(pCirc,0);
	mpf_set_d(aux1,0);
	mpf_set_d(aux2,0);

	gmp_randinit_default(state);
	gmp_randseed_ui(state,time(NULL));

    start=clock();
	for(i=0;i<pontos;i++)
	{
		mpf_urandomb(x,state,100);
		mpf_urandomb(y,state,100);  //X e Y recebem numeros randomicos

		mpf_mul(aux1,x,x);
		mpf_mul(aux2,y,y);
		mpf_add(z,aux1,aux2);   //z = (x*x)+(y*y)

		if(mpf_cmp_d(z, 1) <= 0){
			mpf_add_ui(pCirc,pCirc,1);     //Numero de pontos no Circulo
		}

	}

	mpf_set_ui(aux1,pontos);
	mpf_div(aux2,pCirc,aux1);
	mpf_mul_ui(pi,aux2,4);  //pi=(Numero total de pontos no circulo/Numero total de pontos)*4

    end=clock();
   	gmp_printf("Pi = %.100Ff\n",pi);
   	printf("\n--Tempo %ld--\n",(end - start)/CLOCKS_PER_SEC);

	mpf_clear(aux1);
	mpf_clear(aux2);
	mpf_clear(x);
	mpf_clear(y);
	mpf_clear(z);
	mpf_clear(pCirc);
	mpf_clear(pi);

	return 0;

}
